<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Questionnaire extends Model
{
    protected $table='questionnaire';
    protected $guarded = [];
    public $timestamps = false;
    public function wxusers()
    {
        return $this->belongsToMany('App\Models\Wxuser','questionnaire_wxuser','questionnaire_id','wxuser_id');
    }

    public function questions()
    {
        return $this->hasMany('App\Models\Question');
    }

    public function isAnswered($user_id){
        $user = $this->wxusers()->find($user_id);
        return (!empty($user)&&$this->count()>0)?true:false;
    }
}
